// 启动类型[0.未知,1.APP或微信启动,2.计费卡启动,3.不计费卡启动,4.按钮或屏幕启动,5.擦枪启动,6.命令启动,7.桩定时启动,8.受电弓启动,9.互联互通启动,10.辅枪启动]

// 当前状态状态：00：空闲，0B：插枪空闲，01：充电中，02XX：故障，03：车位占用，04：维护中
//06：在建中，05：离线，07：桩程序升级，08：预约等待充电中，09：储能车储能中，99：删除，FF：锁定
import {sessionManager} from "./sessionStorage";
import { injectIntl } from 'react-intl';
import moment from "moment/moment";
let locale=sessionManager.get('locale');
let flag=true;
if(locale==='en'){
    flag=false
}



export let currentStatus=(param)=>{
    if(param==='00'){
        param='空闲'
    }else if(param==='0B'){
        param='已插枪'
    }else if(param==='01'){
        param='充电中'
    }else if(param.includes('02')){
        param='故障'
    }else if(param==='03'){
        param='车位占用'
    }else if(param==='04'){
        param='维护中'
    }else if(param==='06'){
        param='在建中'
    }else if(param==='05'){
        param='离线'
    }else if(param==='07'){
        param='桩程序升级'
    }else if(param==='08'){
        param='预约等待充电中'
    }else if(param==='09'){
        param='储能车储能中'
    }else if(param==='99'){
        param='删除'
    }else if(param==='FF'){
        param='锁定'
    }else{
        param='未知'
    }
    return param
}

export let transEPrice=(param)=>{
    if(param===1){
        param='峰时'
    }else if(param===2){
        param='尖时'
    }else if(param===3){
        param='谷时'
    }else if(param===4){
        param='平时'
    }
    return param
}

export let chargeTypeJson = [
  {
    name: '全部',
    status: ''
  },
  {
    name: '交流',
    status: '0'
  },
  {
      name: '直流',
    status: '1'
  }
]

export let stubGpTypeJson = [
  {
    name: '全部',
    status: ''
  },
  {
      name: '自营',
    status: '1'
  },
  {
      name: '非自营',
    status: '0'
  }
]

export let orderStatusJson = [
  {
      name: '全部',
      status: ''
  },
  {
      name: '充电中',
      status: '1',
  },
  {
      name: '充电完成',
      status: '9'
  }
]

export let placeTypeJson = [
  {
    name: '全部',
    status: ''
  },
  {
    name: '居住地',
    status: '1222',
  },
  {
    name: '目的地',
    status: '1223'
  },
  {
    name: '工作地',
    status: '1224'
  }
]


export let currentStatusJSON=[
    {name:"空闲",status:'00'},
    {name:"已插枪",status:'0B'},
    {name:"充电中",status:'01'},
    {name:"故障",status:'02'},
    {name:"车位占用",status:'03'},
    {name:"维护中",status:'04'},
    {name:"在建中",status:'06'},
    {name:"桩程序升级",status:'07'},
    {name:"预约等待充电中",status:'08'},
    {name:"储能车储能中",status:'09'},
    {name:"删除",status:'99'},
    {name:"锁定",status:'FF'},
]

export let stubMonitorJSON=[
    {name:"空闲",status:'00'},
    {name:"已插枪",status:'0B'},
    {name:"充电中",status:'01'},
    {name:"故障",status:'02'},
    {name:"离线",status:'05'},
    {name:"其他",status:'99'},
];



export default  (data)=> {
    if(data===0){
        data=flag?"未知":"unknown"
    }else if(data===1){
        data=flag?"APP或微信启动":'App or Wexin launch'
    }else if(data===2){
        data=flag?"计费卡启动":"billing card launch"
    }else if(data===3){
        data=flag?"不计费卡启动":"non-paid card launch"
    }else if(data===4){
        data=flag?"按钮或屏幕启动":"button or screen launch"
    }else if(data===5){
        data=flag?"擦枪启动":"clean guns launch"
    }else if(data===6){
        data=flag?"命令启动":"command launch"
    }else if(data===7){
        data=flag?"桩定时启动":"Pile timing launch"
    }else if(data===8){
        data=flag?"受电弓启动":"pantograph launch"
    }else if(data===9){
        data=flag?"互联互通启动":"interconnection and interworking launch"
    }else if(data===10){
        data=flag?"辅枪启动":"Auxiliary gun launch"
    }else{
        data=""
    }
    return data
}

export  const startTypeJSON=[
    {name:flag?"未知":"unknown",id:0},
    {name:flag?"APP或微信启动":'App or Wexin launch',id:1},
    {name:flag?"计费卡启动":"billing card launch",id:2},
    {name:flag?"不计费卡启动":"non-paid card launch",id:3},
    {name:flag?"按钮或屏幕启动":"button or screen launch",id:4},
    {name:flag?"擦枪启动":"clean guns launch",id:5},
    {name:flag?"命令启动":"command launch",id:6},
    {name:flag?"桩定时启动":"Pile timing launch",id:7},
    {name:flag?"受电弓启动":"pantograph launch",id:8},
    {name:flag?"互联互通启动":"interconnection and interworking launch",id:9},
    {name:flag?"辅枪启动":"Auxiliary gun launch",id:10},
]


export let UUID=()=> {
    let d = new Date().getTime();
    let uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
        let r = (d + Math.random()*16)%16 | 0;
        d = Math.floor(d/16);
        return (c=='x' ? r : (r&0x3|0x8)).toString(16);
    });
    return uuid;
}

export let fillMonths=()=>{
    let months=[];
    let curMonths=moment().format('YYYY-MM');
    let len=moment(curMonths).daysInMonth();
    for(let i=0;i<len;i++){
        let index=i+1;
        if(index<10){
            index="0"+index
        }
        months.push({days:index.toString()})
    }
    return months;
}

export let quickSort2 =function(arr,params) {
    if (arr.length <= 1) { return arr; }
    let pivotIndex = Math.floor(arr.length / 2);
    let pivot = arr.splice(pivotIndex, 1)[0];
    let left = [];
    let right = [];
    for (let i = 0; i < arr.length; i++){
        if (arr[i][params] < pivot[params]) {
            left.push(arr[i]);
        } else {
            right.push(arr[i]);
        }
    }
    return quickSort2(left,params).concat([pivot], quickSort2(right,params));
};

export let authFun=(button, dom) => {
    Array.from(dom).map((k) => {
        let authID = k.getAttribute("data-auth");
        let flag = button.some((item) => {
            return item == authID;
        });
        if (flag) {
            delete k.dataset.auth
        }
    });
};

export let interStatus=(param)=>{
    if(param===0){
        param='未知'
    }else if(param===1){
        param='建设中'
    }else if(param===5){
        param='关闭下线'
    }else if(param===6){
        param='维护中'
    }else if(param===50){
        param='正常使用'
    }
    return param
}

//补全数据，缺失数据补全
